package com.sugon.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.ModuleMaintainPlanItemDao;
import com.sugon.entity.ModuleMaintainPlanItemEntity;
import com.sugon.service.ModuleMaintainPlanItemService;
import com.sugon.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 模具维护规程关联Service实现类
 *
 * @author sugon
 * @date 2020-08-14 09:42:50
 */
@Service("moduleMaintainPlanItemService")
public class ModuleMaintainPlanItemServiceImpl implements ModuleMaintainPlanItemService {

    @Autowired
    private ModuleMaintainPlanItemDao moduleMaintainPlanItemDao;

    /**
     * @param id 主键
     * @return
     */
    @Override
    public ModuleMaintainPlanItemEntity queryObject(String id) {
        return moduleMaintainPlanItemDao.queryObject(id);
    }

    /**
     * @param map 参数
     * @return
     */
    @Override
    public List<ModuleMaintainPlanItemEntity> queryList(Map<String, Object> map) {
        return moduleMaintainPlanItemDao.queryList(map);
    }

    /**
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return moduleMaintainPlanItemDao.queryTotal(map);
    }

    /**
     * @param moduleMaintainPlanItem 实体
     * @return
     */
    @Override
    public int save(ModuleMaintainPlanItemEntity moduleMaintainPlanItem) {
        moduleMaintainPlanItem.setId(RandomUtil.randomString(32));
        moduleMaintainPlanItem.setDelFlag(Constant.IS_NOT_DEL_INT);
        moduleMaintainPlanItem.setIsExecuted(0);
        return moduleMaintainPlanItemDao.save(moduleMaintainPlanItem);
    }

    /**
     * @param moduleMaintainPlanItem 实体
     * @return
     */
    @Override
    public int update(ModuleMaintainPlanItemEntity moduleMaintainPlanItem) {
        return moduleMaintainPlanItemDao.update(moduleMaintainPlanItem);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return moduleMaintainPlanItemDao.delete(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return moduleMaintainPlanItemDao.deleteBatch(ids);
    }

    /**
     * 是否存在
     *
     * @param moduleMaintenancePlanId   模具维护计划ID
     * @param moduleMaintenanceOptionId 模具维护项ID
     * @return
     */
    @Override
    public boolean isExists(String moduleMaintenancePlanId, String moduleMaintenanceOptionId) {
        Map<String, Object> param = new HashMap<>(2);
        param.put("maintainPlan", moduleMaintenancePlanId);
        param.put("maintainBase", moduleMaintenanceOptionId);
        return queryTotal(param) > 0;
    }

    /**
     * @param map 参数
     * @return
     */
    @Override
    public List<ModuleMaintainPlanItemEntity> queryListByPlan(Map<String, Object> map) {
        return moduleMaintainPlanItemDao.queryListByPlan(map);
    }

    /**
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotalByPlan(Map<String, Object> map) {
        return moduleMaintainPlanItemDao.queryTotalByPlan(map);
    }

}
